<?php

declare(strict_types=1);

namespace App\Job;

use App\Helpers\ConfigUtil;
use App\Model\Message;
use Hyperf\AsyncQueue\Job;
use Psr\Container\ContainerInterface;

class PushMsgJob extends Job
{
    /**
     * 参数
     */
    public $params;

    const TYPE_ONLINE_PUSH = 1;

    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     *
     * @var int
     */
    protected $maxAttempts = 1;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
        $pushType = $this->params['push_type'] ?? 0;
        if (!$pushType) return;

        $imAccount = $this->params['im_account'];
        switch ($pushType) {
                //上线后push
            case PushMsgJob::TYPE_ONLINE_PUSH:
                $msg = ConfigUtil::pickMaleWakeupMsg();
                Message::sendPush($imAccount, $msg, true);
                break;
        }
        log_info(__CLASS__ . "==" . json_encode($this->params));
        return;
    }
}
